<link rel="stylesheet" href="css/cashier_mana/reservation.css" />
<link rel="stylesheet" href="css/cashier_mana/spa_frontAccount.css" />
<link rel="stylesheet" href="assets/css/ui.jqgrid.css" />
<!-- 数字键盘样式 -->
<link rel="stylesheet" href="css/plugin/digitalCalculator.css" />
<link rel="stylesheet" href="css/spa_guestList/spa_handMgn.css" />
<link rel="stylesheet" href="css/E_coupon/coupon_get1.css" />
<link rel="stylesheet" href="css/E_coupon/coupon_get2.css" />

<title data-i18n="入账">入账</title>
<!-- 遮罩层 -->
<div id="pageOverlay" class="hide"></div>
<!-- 等待动画 -->
<div id="loading" class="loading hide">						
	<i class="ace-icon fa fa-spinner fa-spin orange bigger-250"></i>
</div>
<div class="row">
	<div id="pageBody" class="col-sm-12 no-margin no-padding">
		<div id="pageLeft" class="col-sm-4 no-margin no-padding"></div>
		<div id="pageRight" class="col-sm-8 no-margin no-padding">
			<div id="menuContainer">
				<div id="goodsCb" class="widget-box goodsCb" style="height:110px;">
				</div>
				<div id="goodsMenu" class="widget-box">
					<div class="pd_info"></div>
				</div>
			</div>
			<div id="settleAccounts" style="display:none;">
				<div class="widget-box">
					<div class="widget-body">
						<div class="widget-box" style="margin:0px;">
							<div id="ledgerHeader" class="widget-body"></div>
							<div id="frontPosMessInfo"></div> 
						</div>
						<div id="posorderBill">
							<div class="widget-box" style="margin:0px;display:flex;">
								<div id="connectList" class="widget-body" style="width:0%;">
									
								</div>
								<div id="billList" class="widget-body" style="overflow-y:auto;width:100%;border-left:1px solid #cccccc;">
									<table class="table table-bordered" style="border:0; margin-bottom:0px;"> 
										<tbody style="font-size:16px;">                   
											<tr>  
												<td data-i18n="原消费金额" class="center;" style="border: 0px;">原消费金额</td> 
												<td class="total_price" style="text-align:right;border: 0px;">0.00</td>         
											</tr>
										</tbody>    
									</table>	
									<div class="tableMoney">
										<div class="money_top"> 
											<div class="money_left_info"></div>
											<table class="table table-striped table-bordered" style="border:0;"> 
												<tbody id="tableMethodTable" style="font-size:16px;">                   
													
												</tbody>    
											</table> 
										</div>	
										<div class="pay_price"  style="font-size:25px">
											<label style="font-size:25px" data-i18n="应收:">应收:</label>
											<span class="pay_p">￥0.00</span>
										</div>   
									</div>
								</div>
							</div>
							<div id="jzBtnContent" class="money_center" style="position:relative;"><!-- margin-top:5px; --> 
							</div>
						</div>
					</div>
				</div>
			</div>
			
			<div class="widget-box" style="height:63px;">
				<div class="clearfix">
					<div class="pull-left">
						<button type="button" class="btn btn-app btn-sm btn-light accountCode" data-type="code" style="height:58px;">
							<span data-i18n="助记码" class="blue">助记码</span>
						</button>
						<button type="button" class="btn btn-app btn-sm btn-light accountCode" data-type="type" style="height:58px;display:none;">
							<span data-i18n="分类" class="blue">分类</span>
						</button>
					</div>
					<div class="pull-right">
						<button type="button" class="btn btn-app btn-sm btn-purple dishesAccounts" style="background:rgb(152, 137, 193) !important;height:58px;">
							<span data-i18n="结帐">结帐</span>
						</button>
						<button type="button" class="btn btn-app btn-sm btn-purple dishesAccounts" style="background:rgb(137, 193, 139) !important;height:58px;display:none;">
							<span data-i18n="入账">入账</span>
						</button>
						<button id="btnBack" type="button" class="btn btn-app btn-sm btn-light" style="height:58px;">
							<span data-i18n="返回" class="blue">返回</span>
						</button>
					</div>
				</div>
			</div>
			
		</div>
	
	</div>
</div>
<!-- 国际化 --> 
<script type="text/javascript">
	//加载资源文件
	var scripts = [
                   "js/plugin/jquery.jqGrid.js",
				   "assets/js/jqGrid/i18n/grid.locale-cn.js",
				   //sql查询
                   'js/plugin/jsonsql.js',
				   "js/cashier_mana/global.js",
				   "js/cashier_mana/jquery.service.spa_front_account_search.js",//查找
				   "js/cashier_mana/jquery.service.spa_front_account_type.js",//录入项目
				   "js/cashier_mana/jquery.service.spa_front_account_menu.js",//录入菜单
				   "js/cashier_mana/jquery.service.spa_init_sellte_account.js",//初始结账
				   "assets/js/fuelux/fuelux.spinner.js",
				   "assets/js/ace/elements.spinner.js",
				   ]; 
	//全窗口变量
	var ins_argjson={};
	$(".page-content-area").ace_ajax("loadScripts",scripts,function(){
		ins_argjson.operGrid = 1;
		var session = {session:{bmh:$.HSAPI_HEADERS.bmh,userid:$.HSAPI_USERID,"username":$.HSAPI_USERNAME}};
		$("link[href='css/cashier_mana/spa_guestAccount.css']").remove();
		
		ins_argjson.session = session.session;
		document.title = $.i18n.propJsp("入账");
		
		setSize();
		//加载插件
		jf_retrieve_plugin_service();
		//页面事件
		jf_bindEvent();
	})
	
	function setSize(){
		//页面右侧(计算菜品大类和菜谱的高度)
		var winh = $(window).height();
		var offset = parseFloat($(".page-content").css("padding-top"));//页面偏差
		var top = $("#menuContainer").offset().top;
		var h = winh - top - 69 + offset;
		$("#menuContainer").css({"height":h});
		$("#settleAccounts").css({"height":h,"width":$("#menuContainer").width()});
		
		ins_argjson.width = $("#menuContainer").width();
		ins_argjson.height = h;
		
		var top1 = $("#goodsMenu").find(".pd_info").offset().top;
		var hh = h - (top1 - top);
		$("#goodsMenu").find(".pd_info").css("height",hh);
	}
	
	function jf_retrieve_plugin_service(){
		//查询手牌
		$("#pageLeft").spa_front_account_search({
			wait : wait,
			goon : goon,
			bmh : ins_argjson.session.bmh,
			dataBack : function(data){
				//初始结账
				initSettleAccounts(data);
			},
			closeBack : function(){},
			brzdBack : function(ct_brzd){
				$.spa_front_account_menu.param.ct_brzd = ct_brzd;
				$.spa_front_account_type.param.ct_brzd = ct_brzd;
			},
		});
		
		//入账商品
		$("#goodsMenu").spa_front_account_menu({
			wait : wait,
			goon : goon,
			bmh : ins_argjson.session.bmh,
			width : $("#pageRight").width(),
			height : $("#goodsMenu").find(".pd_info").height(),
			dataBack : function(){
				$.spa_front_account_search.thSearch();
			},
			closeBack : function(){},
		})
		
		//入账商品大类
		$("#goodsCb").spa_front_account_type({
			ds : [],
			wait : wait,
			goon : goon,
			bmh : ins_argjson.session.bmh,
			width : $("#pageRight").width(),
			clickBack : function(ds){
				$.spa_front_account_menu.param.page = 1;
				$.spa_front_account_menu.param.cb_bh = ds.bh
				$.spa_front_account_menu.initDs();
			},
			pymBack : function(pym){
				$.spa_front_account_menu.param.page = 1;
				$.spa_front_account_menu.param.pym = pym;
				$.spa_front_account_menu.initDs();
			},
			dataBack : function(jdh){
			},
			closeBack : function(){
			}
		});
		
		 var ds = {ct_brzd:[{}],ct_brxsxm:[],amount:[{}]};
		initSettleAccounts(ds);
	}
	
	function initSettleAccounts(data){
		var payment = $.parseJSON(localStorage.getItem("payment"))
		var ho_dcode = $.parseJSON(localStorage.getItem("ho_dcode"))
		$("#settleAccounts").spa_init_sellte_account({
			data : data,
			ct_brzd : data.ct_brzd[0]||"",
			ct_brxsxm : data.ct_brxsxm||"",
			amount : data.amount[0]||"",
// 			payment : data.payment||"",
// 			ho_dcode : data.ho_dcode||"",
			payment : payment,
			ho_dcode : ho_dcode,
			ledgerHeader : "",//头部信息ID
			width : ins_argjson.width,
			height : ins_argjson.height,
			dataBack : function(oper){
				if(oper=="clear"){//清楚数据
					$.spa_front_account_search.clearAccountInfo();
				}else if(oper=="fresh"){//刷新数据
					$.spa_front_account_search.thSearch();
				}
			},
			refreshBack : function(){
				$.spa_front_account_search.thSearch();
			},
			closeBack : function(){}
		})
	}
	
	function wait(){
		$("#pageOverlay").removeClass("hide");
		$("#loading").removeClass("hide");
	}
	
	function goon(){
		$("#pageOverlay").addClass("hide");
		$("#loading").addClass("hide");
	}
	
	function jf_bindEvent(){
		//助记码/分类切换
		$(".accountCode").unbind("click").click(function(){
			$(".accountCode").toggle();
			var type = $(this).data("type");
// 			console.log(type)
			$("#goodsMenu").find(".pd_info").empty();
			if(type=="code"){
				$("#goodsCb").css({"height":"136"});
				setSize();
				$.spa_front_account_type.initCodeHtml();
			}else if(type=="type"){
				$("#goodsCb").css({"height":"110"});
				$("#nav-search").remove();
				setSize();
				$.spa_front_account_menu.param.pym = "";
				$.spa_front_account_type.initGoodsCbHtml();
			}
		})
		
		//返回
		$("#btnBack").unbind("click").click(function(){
			history.go(-1);
		})
		
		//结账/入账
		$(".dishesAccounts").unbind("click").click(function(){
// 			alert(ins_argjson.no);
			$(".dishesAccounts").toggle();
			$("#menuContainer,#settleAccounts").toggle();
		})
	}
	
</script>